package wordit.impl;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;

import wordit.Dictionary;

public class PlainTextDictionary implements Dictionary {

	private final Set<String> dict;

	public PlainTextDictionary(String filename) throws IOException {
		dict = new HashSet<String>();
		loadDictionaryFile(filename);
	}

	private void loadDictionaryFile(String filename) throws IOException {
		BufferedReader reader = new BufferedReader(new FileReader(filename));
		dict.clear();

		String word;
		while ((word = reader.readLine()) != null) {
			dict.add(word);
		}
	}

	@Override
	public double scoreWord(String seq) {
		return dict.contains(seq.toLowerCase()) ? 1.0 : 0;
	}
}
